<?php 
$user=$session->read('User');
$companyid=$session->read("companyid");
?>
<div class="right_side_operate_area">
	<div class="right_side_title left">
    	<h2>
		<?php 
		$companyname=$session->read("companyname");
		echo $html->link($companyname,"/companys/showinfosummary/".$companyid);
		?>
    	</h2>
    	<div class='clear'></div>
    </div>
    <div class="right item_add_btn">
		<?php 
			$cuser=$session->read('User');
			if($form->value('CompTalent.id')){
			$str_title=__("Edit",true);
			}else{
			$str_title=__("Add",true);
			}
    		echo $html->link(__("Cancel",true).$str_title,"/companys/talent/");
    	?>
	</div>
    <div class="clear"></div>
</div>

<div class="right_side_scollbar">
	<div class="detail_info_panel">
		<?php
		echo $form->create('Company', array('url' => "/companys/edittalent",'id'=>'talentform','enctype'=>'multipart/form-data','onsubmit'=>"return checksave()"));
		?>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"><font style="color:red">*</font>项目名称：</div>
			    <div class="form_right_e_input left">
			    	<?php echo $form->text('CompTalent.declare_name',array("maxlength"=>"100","style"=>"width:147px"));?>
			    </div>
			    <div id='talentnamememessage' style='display:none;' class="error_message">请选择名称</div>
			</div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"><font style="color:red">*</font>申报时间：</div>
			    <div class="form_right_e_input form_date_picker left">
			    	<?php echo $form->text('CompTalent.declare_time',array("maxlength"=>"10","onfocus"=>"WdatePicker()","style"=>"width:130px"));?>
			    </div>
			    <div id='talenttimemessage' style='display:none;' class="error_message">请选择时间</div>
			</div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"><font style="color:red">*</font>申报类型：</div>
			    <div class="form_right_e_input left">
				    <?php $selectdeclaretype=$form->value("CompTalent.type_id"); ?>
				    <?php echo $form->hidden('CompTalent.type_id') ;?>
				    <?php echo $form->select('talmenu',$declaretype, $selectdeclaretype, array("onchange"=>"selecttype(this)","class"=>"left"),null);?>
				    <div id="selectone" class="left"></div>
				    <div id="selecttwo" class="left"></div>
				    
				    <?php
				    if($id){
					    $tvalue=$form->value('CompTalent.type_id');
					    classregistry::init('Talstack')->showtname($tvalue);
					    $tid=rtrim(classregistry::init('Talstack')->tid,"/");
					    echo "<div id='typelist' style='display:none'>".$tid."</div>";
					    classregistry::init('Talstack')->tid="";
				    }
				    ?>
			    </div>
			    <div id='talenttypeemessage' style='display:none;' class="error_message">请选择类型</div>
			</div>
		</div>
		<div class="details_item_line" style="display:none;">
			<div class="details_item">
			    <div class="form_left_title left">申报状态：</div>
			   <div class="form_right_e_input left">
			    	 <?php echo $form->select('CompTalent.declarate_status',$statues,null,null,null);?>
			    </div>
			    <div id='talenttypememessage' style='display:none;' class="error_message">请选择状态</div>
			</div>			
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left">立项时间：</div>
			    <div class="form_right_e_input form_date_picker left">
			    <?php echo $form->text('CompTalent.project_time',array("maxlength"=>"10","onfocus"=>"WdatePicker()","style"=>"width:130px"));?>
			    </div>
			</div>

		</div>
		<div class="details_item_line">
			<div class="details_item">
                <div class="form_left_title left">获奖金额：</div>
                <div class="form_right_e_input left">
                <?php echo $form->text('CompTalent.award',array("placeholder"=>"0.00","onkeydown"=>"checkpricekeyup(this,event)","style"=>"width:70px","maxlength"=>"10"));?> 万元</div>
            </div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_right_e_input left">
               		 <?php echo $form->checkbox('CompTalent.isreview',array("style"=>"margin-left:30px;margin-top:5px"));?> 
                </div>
                <div class="form_left_title left" style="width:auto">是否通过中期评审：</div>
			    <div class="form_right_e_input left">
               		 <?php echo $form->checkbox('CompTalent.isexamination',array("style"=>"margin-left:30px;margin-top:5px"));?> 
                </div>
                <div class="form_left_title left" style="width:auto">是否通过结题：</div>
            </div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
                <div class="form_left_title left">项目介绍：</div>
                <div class="form_right_e_input left">
                <?php echo $form->textarea('CompTalent.content',array("style"=>"width:200px;height:50px;"));?>
                </div>
                 <div id='talentcontentmemessage' style='display:none;' class="error_message">项目介绍最大字数不超过50</div>
            </div>
		</div>
		
		
		
		<?php if(($form->value('CompTalent.public')=="1")||$user['isadmin'] || $user['isgroupadmin']){ ?>
		<?php foreach($filetypes as $key=>$ftype){?>
		<div class="details_item_line" style="display:none;">
			<div class="details_item">
			    <div class="form_left_title left"><?php echo $ftype?>：</div>
			    <div class="form_right_input left">
			    <?php 
        		 	$fildisplay="none";
    		 		if(!empty($attachments)){
						foreach($attachments as $attachment) {
							if($key==$attachment["cvid"]){
								$fildisplay="block";
							}
						}
					}
				 ?>
            	<div class="file_category_list" style="display:<?php echo $fildisplay?>">
	        		<div id="filelist<?php echo $key?>" class="file_lists">
	        			<ul class="file_attach">
		                	<?php
		                	$dan="'";
		                	if($attachments){
			                	foreach($attachments as $attachment) {
			                			if($key==$attachment["cvid"]){
											echo "<li>";
											echo "<span>".$html->link($attachment["file_name"],'/projects/download/'.$attachment["id"],null)."</span>";
											echo "<span class='source_upload_date'>".date("Y-m-d",strtotime($attachment["created"]))."</span>";
											if($action->checkPermissions($user,$companyid)){
												echo '<span class="source_upload_delete"><a title="删除" onclick="delfile(this,'.$dan.$attachment["id"].$dan.','.$dan.$key.$dan.')" href="javascript:void(0)"></a></span>';
											}
											echo "</li>";
										}
								}
							}
		                	?>
		                </ul>
	                </div>
	            </div>
			    <div class="left text_box"> 
					<div class="file_add_box">
						<input type="file" id="upload[]" name="upload<?php echo $key?>[]" />
					</div>
				</div>
				<div class="clear"></div>
				<div id="add2<?php echo $key?>" class="left filelist"></div>
				<div class="left clear">
					<div class="left add_sub_file_btn">
						<span onclick="addmore('<?php echo $key?>')" href="#"><?php echo $html->image('list-add.png')?></span>&nbsp;
						<span onclick="removemore('<?php echo $key?>')" href="#"><?php echo $html->image('list-remove.png')?></span>
					</div>
				</div>
			 </div>
			</div>
		</div>
		<?php }?>
		<div class="details_item_line" style="display:none;">
			<div class="details_item">
			    <div class="form_left_title left">附件公开：</div>
			     <div class="form_right_input left">
		              <?php
		              $attributes=array('legend'=>false);
		              echo $form->radio('CompTalent.public',array("1"=>"是","0"=>"否"),$attributes);?>	
		       </div>
			</div>	
		</div>	
		<?php }?> 
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left"></div>
				<div class="form_add_submit left">
			   		 <?php echo $form->submit(__('Save',true), array("id"=>"adduser","name"=>"submit","class"=>"buttom","div"=>false));  ?>
			    	 <?php echo $form->hidden('CompTalent.id') ;?>
			    	 <?php echo $form->hidden('CompTalent.cid',array("value"=>$companyid)) ;?>
			    	  <?php echo $form->hidden('CompTalent.creater') ;?>
			    </div>
			</div>
		</div>
		</form>
	</div>
</div>
<?php echo $this->element('delfileconfirm',array("title"=>"删除提示","message"=>"你确定要删除吗？")) ?>
<script>
$("#CompTalentDeclarateType option:first").html('请选择状态');
$("#CompTalentName option:first").html('请选择名称');
function checksave(){
	var typeid="";
	var tid2=$("#selecttwo").find("select").val();
	var tid1=$("#selectone").find("select").val();
	if($("#selecttwo").html()!="" && tid2!=null && tid2!=""){
		typeid=tid2;
	}
	else if($("#selectone").html()!="" && tid1!=null && tid1!=""){
		typeid=tid1;
	}
	else if($("#CompanyTalmenu").val()!=""){
		typeid=$("#CompanyTalmenu").val();
	}
	$("#CompTalentTypeId").val(typeid);
	
	if($("#CompTalentDeclareName").val().trim() == ''){
		$("#talentnamememessage").css('display','block');
		return false;
	}else{
		$("#talentnamememessage").css('display','none');
	}
	
	if($("#CompTalentDeclareTime").val().trim() == ''){
		$("#talenttimemessage").css('display','block');
		return false;
	}else{
		$("#talenttimemessage").css('display','none');
	}
	if($("#CompanyTalmenu").val().trim() == ''){
		$("#talenttypeemessage").css('display','block');
		return false;
	}else{
		$("#talenttypeemessage").css('display','none');
	}
	if($("#CompantContent").length > 50){
		$("#talentcontentmemessage").css('display','block');
			return false;
		}else{
			$("#talenttypeemessage").css('display','none');
			}
	
//	if($("#CompTalentDeclarateStatus").val().trim() == ''){
//			$("#talenttypememessage").css('display','block');
//			return false;
//     }else{
//	 	 $("#talenttypememessage").css('display','none');
//	 }	  		  
}	
var webpath=$("#getpath").attr('href');
var ddlid1="";
var ddlid2="";
var ddls1="";
var ddls2="";
function selecttype(obj,sub){
	if(obj!=null && obj.value!=""){
	var path=webpath+'companys/gettname/'+obj.value+'/'+Math.random();
	$.ajax({     	   
	    	url: path, 
	        success:function(data){
        		if(sub=="1"){
        			if(data){
        				$("#selecttwo").html(data);
        				if(ddlid2!=""){
		        			$("#talmenu"+ddlid2).val(ddls2);
			        		var objd2=document.getElementById("talmenu"+ddlid2);
			        		ddlid2="";ddls2="";
			        		selecttype(objd2,1);
		        		}
        			}else{
        				if($(obj).parent().parent().attr("id")=="selecttwo"){
        					
        				}else{
        					$("#selecttwo").html("");
        				}
        			}
        		}else{
        			$("#selectone").html(data);
        			$("#selecttwo").html("");
        		}
        		if(ddlid1!=""){
        			$("#talmenu"+ddlid1).val(ddls1);
	        		var objd1=document.getElementById("talmenu"+ddlid1);
	        		ddlid1="";ddls1="";
	        		selecttype(objd1,1);
        		}
        		$("#talmenu"+obj.value).uniform();
		       	$("#selectone").find("#talmenu"+obj.value).change(function() {  
		       		if(this.value==""){
		       			$("#selecttwo").html("");
		       		}
		       	});
	        }      
	     });
	}else{
		if(sub!="1"){
			$("#selectone").html("");
	        $("#selecttwo").html("");
        }
	}
}
var typemenu=$("#typelist").text();
if(typemenu!=""){
	var objtype=typemenu.split('/');
	var olen=objtype.length;
	for(var i=0;i<olen;i++){
		var selected=objtype[i];
		if(i==0){
			$("#CompanyTalmenu").val(selected);
			selecttype(document.getElementById("CompanyTalmenu"));
			ddlid1=selected;
		}
		if(i==1){
			ddls1=selected;ddlid2=selected;
		}
		if(i==2){
			ddls2=selected;
		}
	}
}
</script>